package com.song.tools.songtest.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.song.tools.core.util.ObjectUtils;
import com.song.tools.mvc.manager.BaseManager;
import com.song.tools.songtest.beans.bo.OperateLogBo;
import com.song.tools.songtest.beans.query.OperateLogQuery;
import com.song.tools.songtest.convertor.OperateLogConvertor;
import com.song.tools.songtest.dao.entity.OperateLog;
import com.song.tools.songtest.dao.mapper.OperateLogMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 操作日志表 管理类
 * </p>
 *
 * @author song tools
 * @since 2024-07-16
 */
@Component
public class OperateLogManager extends BaseManager<OperateLog, OperateLogBo, OperateLogMapper, OperateLogQuery, Long, OperateLogConvertor> {

    @Resource
    private OperateLogConvertor operateLogConvertor;

    @Override
    public LambdaQueryWrapper<OperateLog> encapsulateQueryWrapper(OperateLogQuery query) {
        LambdaQueryWrapper<OperateLog> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getId()), OperateLog::getId, query.getId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLogId()), OperateLog::getLogId, query.getLogId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getQueryId()), OperateLog::getQueryId, query.getQueryId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getModule()), OperateLog::getModule, query.getModule());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLogType()), OperateLog::getLogType, query.getLogType());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getContext()), OperateLog::getContext, query.getContext());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getExt()), OperateLog::getExt, query.getExt());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getUserPhone()), OperateLog::getUserPhone, query.getUserPhone());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUser()), OperateLog::getCreateUser, query.getCreateUser());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), OperateLog::getCreateUserId, query.getCreateUserId());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getCreateTimeStart()), OperateLog::getCreateTime, query.getCreateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getCreateTimeEnd()), OperateLog::getCreateTime, query.getCreateTimeEnd());

        return queryWrapper;
    }
}
